from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED
import time


def sleep_task(sleep_time, name):
    print("sleep {} s".format(sleep_time))
    time.sleep(sleep_time)
    print(name)
    print('end')


executor = ThreadPoolExecutor(max_workers=2)

name = 'test'
task1 = executor.submit(sleep_task, 1, name )
task2 = executor.submit(sleep_task, 2, name )
task3 = executor.submit(sleep_task, 3, name )

wait([task1, task2, task3],  return_when=ALL_COMPLETED)

print('main end')